﻿using System;
using System.Collections.Generic;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework;

namespace Ue.Qcdz.Domain.Collectors
{
    public class CollectorService
    {
        private static ICollectorRepository repository;

        static CollectorService()
        {
            CollectorService.repository = RepositoryFactory.GetRepository<ICollectorRepository, Collector>();
        }
        public static Collector GetCollector(object collectorKey)
        {
            return CollectorService.repository.FindBy(collectorKey);
        }

        public static IList<Collector> GetCollector()
        {
            return CollectorService.repository.FindAll();
        }
        public static IDataResult<Collector> GetCollector(ICollectorDataQuery dataQuery)
        {
            return CollectorService.repository.FindBy(dataQuery);
        }

        public static void AddCollector(Collector collector)
        {
            CollectorService.repository.Add(collector);
        }

        public static void RemoveCollector(Collector collector)
        {
            CollectorService.repository.Remove(collector);
        }
        public static void RemoveCollector(object collectorKey)
        {
            Collector collector = CollectorService.repository.FindBy(collectorKey);
            if (collector == null)
            {
                throw new ArgumentOutOfRangeException("collectorKey");
            }

            CollectorService.repository.Remove(collector);
        }

        public static void UpdateCollector(Collector collector)
        {
            CollectorService.repository[collector.Key] = collector;
        }
    }
}
